﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PowerTest.Admin
{
    public partial class frmQLySV : Form
    {
        public static string masua;
        public frmQLySV()
        {
            InitializeComponent();
        }

        private void frmQLySV_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'powerTestDataSet.viewUserSV' table. You can move, or remove it, as needed.
            this.viewUserSVTableAdapter.FillByMaQuyen(this.powerTestDataSet.viewUserSV,"1","2");

        }

        private void dgvSinhVien_SelectionChanged(object sender, EventArgs e)
        {
            if (dgvSinhVien.CurrentRow == null)
            {
                return;
            }
            try
            {
                string ho = dgvSinhVien.CurrentRow.Cells[1].Value.ToString();
                string dem = dgvSinhVien.CurrentRow.Cells[2].Value.ToString();
                string ten = dgvSinhVien.CurrentRow.Cells[3].Value.ToString();
                if (dem == null || dem == "")
                {
                    lblHTen.Text = ho + " " + ten;
                }
                else
                {
                    lblHTen.Text = ho + " " + dem + " " + ten;
                }
            }
            catch
            {
                MessageBox.Show("Lỗi ! \n", "Canh Bao");
            }
        }

        private void btThoat_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btThem_Click(object sender, EventArgs e)
        {
            new frmThemSV().ShowDialog();
            Dispose();
        }

        private void btXoa_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn chắc chắn muốn xóa Sinh Viên \""
                       + lblHTen.Text + "\" có MSSV \""
                       + lblMSSV.Text + "\" khỏi danh sách",
                       "Xac Nhan", MessageBoxButtons.OKCancel,
                       MessageBoxIcon.Warning) == DialogResult.OK)
            {
                try
                {
                    tblSinhVienTableAdapter.DeleteQueryByMSSV(lblMSSV.Text);
                    tblChiTietUserTableAdapter.DeleteQueryByID(lblMSSV.Text);
                    this.viewUserSVTableAdapter.FillByMaQuyen(this.powerTestDataSet.viewUserSV, "1", "2");
                }
                catch
                {
                    MessageBox.Show("Lỗi ràng buộc dữ liệu ! Không thể xóa !\n\n Chi tiết\n\n"
                        , "Canh Bao");

                }
            }
        }

        private void btSua_Click(object sender, EventArgs e)
        {
            masua = lblMSSV.Text;
            new frmSuaTTSV().ShowDialog();
            Dispose();
        }
    }
}